package com.example.controller;

import com.example.entity.Movie;
import com.example.service.MovieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Controller
public class HomeController {

    @Autowired
    private MovieService movieService;

    // 首页
    @GetMapping("/")
    public String index(Model model) {
        // 获取最新电影列表
        List<Movie> latestMovies = movieService.getAllMovies();
        model.addAttribute("latestMovies", latestMovies);

        // 获取热门电影列表（按点击数排序）
        // 这里简化处理，实际应该按点击数排序
        List<Movie> hotMovies = movieService.getAllMovies();
        model.addAttribute("hotMovies", hotMovies);

        return "index";
    }
}
